using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace MTRC.ODMS.Web.SOM.CodeSetup
{
    /// <summary>
    /// Author:SQB
    /// </summary>
    public partial class WorkSubCategoryList : BasePage_SOM
    {
        #region MenuID

        protected override string MenuID
        {
            get
            {
                return "M140806";
            }
        }

        #endregion

        #region Page Init And Load

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(SetLanguage_Click);
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grvData.PageSize = this.GridViewPageDefaultSize();
                SetLanguage();
                SetPageLoad();
            }
        }

        void SetLanguage_Click(object sender, EventArgs e)
        {
            SetLanguage();
        }

 
        private void SetLanguage()
        {
            this.lbl_CodeSetupTitle.Text = this.GetLabel("SOM_CodeSetupWorkSubCategoryList");
            this.lblWorkSubCategory.Text = this.GetLabel("SOM_WorkSubCategory", true);
            this.lblCat.Text = this.GetLabel("SOM_WorkCategory", true);
            this.chkVoid.Text = this.GetLabel("SOM_Voided");
            this.btnSearch.Text = this.GetLabel("COM_Search");
            this.btnAddNew.Text = this.GetLabel("SOM_AddNewAssetLoanItem");
            this.lblDisplay.Text = this.GetLabel("COM_Show", true);
            BindWorkCategory();
            if (this.Request["AdmRegCategoryID"] != null)
            {
                BindData(true);
            }
            else
            {
                BindData(false);
            }
        }

        private void SetPageLoad()
        {
             if (this.Request["AdmRegCategoryID"] != null)
             {
                 this.ddlWorkCategory.SelectedValue = this.Request["AdmRegCategoryID"].ToString();
             }      
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData(false);
        }

        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("WorkSubCategoryEntry.aspx");
        }

        /// <summary>
        /// Bind drop down list Work Category
        /// </summary>
        private void BindWorkCategory()
        {

           DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDAdmRegCategory.GetWorkCategory(this.LangCode,"",true);
           //// BindListControl(this.ddlWorkCategory, "AdmRegCategoryID", "Description", dt, true);

           this.ddlWorkCategory.Items.Clear();
           ddlWorkCategory.DataSource = dt;
           ddlWorkCategory.DataValueField = "AdmRegCategoryID";
           ddlWorkCategory.DataTextField = "Description";
           ddlWorkCategory.DataBind();
           ddlWorkCategory.Items.Insert(0, LiALL());
           ddlWorkCategory.SelectedIndex = 0;


            dt.Dispose();
            dt = null;
        }

        private void BindData(bool loadFromWorkCategory)
        {
            DataTable dt = new DataTable();
            if (loadFromWorkCategory==true)
            {
                dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDAdmRegSubCategory.GetWorkSubCategoryByWorkCategoryID(this.LangCode, int.Parse(this.Request["AdmRegCategoryID"].ToString()));
                //this.txtWorkSubCategory.Text = dt.Rows[0]["Description"].ToString();
                this.chkVoid.Checked = true;
            }
            else
            {
                dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDAdmRegSubCategory.GetWorkSubCategory(this.LangCode,int.Parse(this.ddlWorkCategory.SelectedValue),this.txtWorkSubCategory.Text.Trim(), this.chkVoid.Checked);
            }
            this.grvData.DataSource = dt.DefaultView;
            this.grvData.DataBind();
        }

        protected void grvData_NeedDataBind()
        {
            BindData(false);
        }

        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((HyperLink)e.Row.Cells[6].FindControl("hypEdit")).NavigateUrl = "WorkSubCategoryEntry.aspx?AdmRegSubCategoryID=" + this.grvData.DataKeys[e.Row.RowIndex]["AdmRegSubCategoryID"].ToString();
                ((HyperLink)e.Row.Cells[6].FindControl("hypEdit")).ToolTip = this.GetLabel("SOM_WorkSubCategoryEntry");
            }
        }
    }
}
